Ext.namespace("Dudley");
Ext.namespace("Dudley.lims");

Dudley.lims.PlasmidStrain = function() {

    var myPlasmidData = [];
    var plasmidForm = {};
    var plasmidPanel = {};
    var plasmidHash = null;
    var plasmidCount = null;
    var plasmidMaxNum = null;
    var plasmidBoxNum = null;
    var plasmidStore = null;
    var plasmidLoaded = false;

    function initPlasmidStore(failedCb, callback) {
        loadPlasmidSearchResult(0, null, callback);
    }

    function loadPlasmidSearchResult(index, searchResultJSON, callback) {
    	plasmidStore = loadSolrSearchResult("Plasmid", getPlasmidPagingColumns(), plasmidSolrTranslator, index, searchResultJSON);
        plasmidStore.load({params:{start:0, limit:10}}, callback());		             
    }

    function goSearch(index, plasmidSearchInput, plasmidSearchOption) {
        if (plasmidSearchInput == '') {
                plasmidSearchInput = '*';
        }
        plasmidSearchInput = checkWildcard(plasmidSearchInput);        
        var searchUrl = getSolrSearchUrl(getLuceneTerm(plasmidSearchOption,plasmidSearchInput), 1000, plasmidFields);
        //"plasmidKey,plasmidName,plasmidMarkers,plasmidYeastSelection,plasmidBoxNumber,plasmidDateEntered,plasmidBacterialHost,plasmidContributor,plasmidSavedBy,plasmidYeastOrigin,plasmidBacterialSelection,plasmidComments,plasmidReferences,plasmidPosition,plasmidAccessionId,plasmidMTA,plasmidIsbBoxNumber");
        var searchWin = getSearchLoadingWindow("plasmid-");        
        searchWin.on("show", function () {
            var sb = Ext.getCmp("plasmid-search-statusbar");
            sb.showBusy();
        });
        searchWin.show();
        Ext.Ajax.request({
            url: searchUrl,
            method: "GET",
            success: function(response) {
                var searchResultObj = Ext.util.JSON.decode(response.responseText);
                loadPlasmidSearchResult(index, searchResultObj.response, function() {
                    Ext.getDom("sample-search-result-list").innerHTML = "";
                    Ext.getDom("yo-form").innerHTML = "";
                    searchWin.close();
                    renderPlasmidSearchResult();
                });
            },
            failure: function() {
                eventManager.fireStatusMessageEvent({ text: "Search Results failed for url:" + searchUrl, level: "error" });
            }
        });
    }

    function loadPlasmidPanel() {
       var plasmidSearchForm = getSearchForm("plasmidSearchButtonId", "plasmidSearchInputId", null);
       Ext.getCmp("plasmidSearchButtonId").addListener("click", function(){
			goSearch(0, Ext.getCmp("plasmidSearchInputId").getValue(), "plasmidFields");		
		});		
        var tbarButtons = [
            {
                id: 'showPlasmidSearchResultsId',
                name: 'showPlasmidSearchResults',
                disabled: true,
                text: '<--Search Results',
                icon: "images/back-green.png",
                cls:'x-btn-text-icon',
                listeners: {click:
                        function() {
                            Ext.getDom("yo-form").innerHTML = "";
                            renderPlasmidSearchResult();
                        }
                }
            },
            {
                id: 'searchAllPlasmidId',
                name: 'searchAllPlasmid',
                disabled: false,
                text: 'View All Records',
                icon: "images/search-blue.png",
                cls:'x-btn-text-icon',
                listeners: {click:
                        function() {
                            Ext.getDom("yo-form").innerHTML = "";
                            goSearch(0, '*', 'plasmidKey');
                        }
                }
            },
            {
                id: 'createNewPlasmidId',
                name: 'createNewPlasmid',
                text: 'Create New Plasmid',
                icon: "images/add-green.png",
                cls:'x-btn-text-icon',
                listeners: {click:
                        function() {
                            Dudley.lims.PlasmidStrain.loadNewPlasmid();
                        }
                }
            }
        ];
        plasmidPanel = new Ext.Panel({
            id: "plasmidPanelId",
            autoHeight: true,
            border: true,
            renderTo: "yad-panel",
            title: "Plasmid",
            header: false,
            tbar: tbarButtons,
            items: plasmidSearchForm
        });
        plasmidPanel.on("activate", function () {
            Ext.getDom("yo-panel").innerHTML = "";
            Ext.getDom("yo-form").innerHTML = "";
            Ext.getDom("sample-search-result-list").innerHTML = "";
            if (plasmidLoaded == false) {
                plasmidLoaded = true;
                goSearch(0, 'AB', 'plasmidKey');
            }
            renderPlasmidSearchResult();
        });
    }

    function postPlasmidStrain(createNew) {
        var plasmidJson = new Object();
        var plasmidKey = Ext.getCmp("plasmidKeyId").getValue();
        plasmidJson["plasmidKey"] = plasmidKey;
        plasmidJson["plasmidName"] = Ext.getCmp("plasmidNameId").getValue();
        plasmidJson["plasmidMarkers"] = Ext.getCmp("markersId").getValue();
        plasmidJson["plasmidAccessionId"] = Ext.getCmp("accessionId").getValue();
        plasmidJson["plasmidYeastSelection"] = Ext.getCmp("yeastSelectionId").getValue();
        plasmidJson["plasmidYeastOrigin"] = Ext.getCmp("yeastOriginId").getValue();
        plasmidJson["plasmidBacterialSelection"] = Ext.getCmp("bacterialSelectionId").getValue();
        plasmidJson["plasmidBacterialHost"] = Ext.getCmp("bacterialHostId").getValue();
        plasmidJson["plasmidDateEntered"] = Ext.getCmp("dateEnteredId").getRawValue();
        plasmidJson["plasmidBoxNumber"] = Ext.getCmp("boxNumberId").getValue();
        plasmidJson["plasmidIsbBoxNumber"] = Ext.getCmp("isbBoxNumberId").getValue();
        plasmidJson["plasmidPosition"] = Ext.getCmp("positionId").getValue();
        plasmidJson["plasmidContributor"] = Ext.getCmp("contributorId").getValue();
        plasmidJson["plasmidSavedBy"] = Ext.getCmp("plasmidSavedById").getValue();
        plasmidJson["plasmidComments"] = Ext.getCmp("plasmidCommentsId").getRawValue();
        plasmidJson["plasmidReferences"] = Ext.getCmp("plasmidReferencesId").getRawValue();
        plasmidJson["plasmidMTA"] = Ext.getCmp("mtaId").getRawValue();
        var plasmidCallback = function() {
            limsadmin_obj["limsadminPlasmidCount"] = plasmidMaxNum; 
            limsadmin_obj['limsadminPlasmidMaxNum'] = plasmidMaxNum;
            limsadmin_obj['limsadminPlasmidBoxNum'] = plasmidBoxNum;
			postSolrUpdates(limsadmin_obj, function(){            
                eventManager.fireStatusMessageEvent({ text: "New Plasmid Strain Added Successfully", level: "info" });
                Ext.Msg.alert('Info', "New Plasmid " + plasmidKey + ' Added Successfully');
                Ext.getDom("yo-form").innerHTML = "";
                goSearch(0, plasmidKey, "plasmidFields");
            });
        };
        if (!createNew) {
            plasmidCallback = function() {
                Ext.Msg.alert('Info', plasmidKey + ' Updated Successfully');
                var searchResultsButton = Ext.getCmp("showPlasmidSearchResultsId");
                searchResultsButton.disable();
            };
        }
        postSolrUpdates(plasmidJson, plasmidCallback);
    }


    function loadCreatePlasmidStrain(plasmidHash, callback) {
        var createNew = true;
        var buttons = [
            {
                id: 'createButton',
                name: 'createButton',
                text: 'Create',
                listeners: {click:
                        function() {
                            if (validateCreateUpdatePlasmid()) {
                                postPlasmidStrain(createNew);
                            }
                        }
                }
            }
        ];
        if (plasmidHash != null) {
            if (plasmidHash.genotype != undefined && plasmidHash.genotype == 'Record Deleted') {
                buttons = [];
            } else {
                buttons = [
                    {
                        id: 'updatePlasmidButtonId',
                        name: 'updatePlasmidButton',
                        text: 'Update',
                        listeners: {click:
                                function() {
                                    if (validateCreateUpdatePlasmid()) {
                                        postPlasmidStrain(!createNew);
                                    }
                                }
                        }
                    },
                    {
                        id: 'deletePlasmidButtonId',
                        name: 'deletePlasmidButton',
                        text: 'Delete',
                        //disabled: true,
                        listeners: {click:
                                function() {
                                    var deleteUrl = "/addama-rest/dudley-sample/path/datasource/Plasmid/" + plasmidHash.name + "/annotations/?JSON={deletedStrain:true}";
                                    Ext.Msg.confirm('Message', "Please confirm that you want to delete " + plasmidHash.name + "", function(btn) {
                                        if (btn == 'yes') {
                                            Ext.Ajax.request({
                                                url: deleteUrl,
                                                method: "POST",
                                                success: function() {
                                                    Ext.Msg.alert(plasmidHash.name + " deleted, Plasmid Strains Reloading...");
                                                    goSearch(0, '*', 'All');
                                                },
                                                failure: function() {
                                                    eventManager.fireStatusMessageEvent({ text: "Delete Failed for " + plasmidHash.name, level: "error" });
                                                }
                                            });
                                        }
                                    });
                                }
                        }
                    }
                ];
            }

            if (plasmidHash.comments == null) {
                plasmidHash.comments = "";
            }
            if (plasmidHash.references == null) {
                plasmidHash.references = "";
            }
            if (plasmidHash.mta == null) {
                plasmidHash.mta = "";
            }

        } else {
            plasmidHash = new Object();
            var plasmidMaxInt = parseInt(plasmidMaxNum);
            plasmidBoxNum = parseInt(plasmidBoxNum);
            if (plasmidMaxNum%81 == 0){
                plasmidBoxNum = plasmidBoxNum + 1;
            }
            plasmidHash.boxNumber = plasmidBoxNum;
            plasmidMaxInt = plasmidMaxInt + 1;
            var plasmidCountInt = parseInt(plasmidCount);
            plasmidCountInt = plasmidCountInt + 1;
            plasmidCount = plasmidCountInt + "";
            plasmidHash.name = 'AB' + plasmidMaxInt;
            plasmidMaxNum = plasmidMaxInt + "";
            initStrainJson(plasmidHash);
            if (plasmidHash.comments == null) {
                plasmidHash.comments = "";
            }
            if (plasmidHash.references == null) {
                plasmidHash.references = "";
            }
            if (plasmidHash.mta == null) {
                plasmidHash.mta = "";
            }
        }

        plasmidForm = new Ext.form.FormPanel({
            id: 'plasmidForm',
            method: 'POST',
            autoHeight: true,
            autoScroll: true,
            border: true,
            buttonAlign: 'left',
            buttons: buttons,
            items: [
                new Ext.form.FieldSet({
                    autoHeight: true,
                    border: false,
                    items: [
                        new Ext.form.TextField({
                            id: "plasmidKeyId",
                            fieldLabel: "Key",
                            name: "plasmidKey",
                            value: plasmidHash.name,
                            width: 500,
                            readOnly: true,
                            allowBlank: false,
                            listeners: {
                                render: function(c) {
                                    Ext.QuickTips.register({
                                        target: c,
                                        title: '',
                                        text: 'Unique identifier generated by system'
                                    });
                                }
                            }
                        }),
                        new Ext.form.TextField({
                            id: "plasmidNameId",
                            fieldLabel: "Name",
                            name: "plasmidName",
                            value: plasmidHash.plasmidName,
                            width: 500,
                            allowBlank: false,
                            listeners: {
                                render: function(c) {
                                    Ext.QuickTips.register({
                                        target: c,
                                        title: '',
                                        text: 'Name of the plasmid as published or created'
                                    });
                                }
                            }
                        }),
                        new Ext.form.TextField({
                            id: "accessionId",
                            fieldLabel: "Accession ID",
                            name: "accession",
                            value: plasmidHash.accessionId,
                            width: 500,
                            allowBlank: true,
                            listeners: {
                                render: function(c) {
                                    Ext.QuickTips.register({
                                        target: c,
                                        title: '',
                                        text: 'Name of the database and associated ID'
                                    });
                                }
                            }
                        }),
                        new Ext.form.TextField({
                            id: "markersId",
                            fieldLabel: "Info",
                            name: "markers",
                            value: plasmidHash.markers,
                            width: 500,
                            allowBlank: false,
                            listeners: {
                                render: function(c) {
                                    Ext.QuickTips.register({
                                        target: c,
                                        title: '',
                                        text: 'Detailed description of what is contained in the plasmid including: Selectable markers, promoters and terminators, gene, gemomic elements (centromere, origin of replication, ...)'
                                    });
                                }
                            }
                        }),
                        new Ext.form.TextField({
                            id: "yeastSelectionId",
                            fieldLabel: "Yeast Selection",
                            name: "yeastSelection",
                            value: plasmidHash.yeastSelection,
                            width: 500,
                            allowBlank: false,
                            listeners: {
                                render: function(c) {
                                    Ext.QuickTips.register({
                                        target: c,
                                        title: '',
                                        text: 'Gene in the plasmid used for yeast transformation selection'
                                    });
                                }
                            }
                        }),
                        {
                            xtype: 'combo',
                            id: 'yeastOriginId',
                            fieldLabel: "Yeast Origin",
                            value: plasmidHash.yeastOrigin,
                            width: 100,
                            store: plasmidYeastOriginStore,
                            displayField: 'key',
                            valueField: 'value',
                            selectOnFocus: true,
                            mode: 'local',
                            typeAhead: true,
                            editable: false,
                            triggerAction: 'all',
                            listeners: {
                                render: function(c) {
                                    Ext.QuickTips.register({
                                        target: c,
                                        title: '',
                                        text: 'Whether there is a yeast origin of replication and what it is. Pulldown - None, Cen, 2 Micron'
                                    });
                                }
                            }
                        },
                        new Ext.form.TextField({
                            id: "bacterialHostId",
                            fieldLabel: "Bacterial Host",
                            name: "bacterialHost",
                            value: plasmidHash.bacterialHost,
                            width: 500,
                            allowBlank: false,
                            listeners: {
                                render: function(c) {
                                    Ext.QuickTips.register({
                                        target: c,
                                        title: '',
                                        text: 'Strain name of the bacteria containing the plasmid'
                                    });
                                }
                            }
                        }),
                        new Ext.form.TextField({
                            id: "bacterialSelectionId",
                            fieldLabel: "Bacterial Selection",
                            name: "bacterialSelection",
                            value: plasmidHash.bacterialSelection,
                            width: 500,
                            allowBlank: false,
                            listeners: {
                                render: function(c) {
                                    Ext.QuickTips.register({
                                        target: c,
                                        title: '',
                                        text: 'Gene in the plasmid used for yeast transformation selection'
                                    });
                                }
                            }
                        }),
                        new Ext.form.TextField({
                            id: "contributorId",
                            fieldLabel: "Contributor",
                            name: "contributor",
                            value: plasmidHash.contributor,
                            size: 500,
                            allowBlank: true,
                            listeners: {
                                render: function(c) {
                                    Ext.QuickTips.register({
                                        target: c,
                                        title: '',
                                        text: 'Lab or organization from which the plasmid was obtained.'
                                    });
                                }
                            }
                        }),
                        new Ext.form.TextField({
                            id: "plasmidSavedById",
                            fieldLabel: "Saved by",
                            value: plasmidHash.savedBy,
                            width: 500,
                            allowBlank: true,
                            listeners: {
                                render: function(c) {
                                    Ext.QuickTips.register({
                                        target: c,
                                        title: '',
                                        text: 'Person saving this strain into LIMS'
                                    });
                                }
                            }
                        }),
                        {
                            layout: 'hbox',
                            width: 500,
                            fieldLabel: 'Physical Location',
                            msgTarget: 'under',
                            items: [
                                {
                                    xtype: 'displayfield',
                                    value: '&nbsp;Box number:&nbsp;'
                                },
                                new Ext.form.TextField({
                                    id: "boxNumberId",
                                    name: "boxNumber",
                                    value: plasmidHash.boxNumber,
                                    width: 75,
                                    allowBlank: false,
                                    listeners: {
                                        render: function(c) {
                                            Ext.QuickTips.register({
                                                target: c,
                                                title: '',
                                                text: 'Strain box number'
                                            });
                                        }
                                    }
                                }),
                                {
                                    xtype: 'displayfield',
                                    value: '&nbsp;ISB number:&nbsp;'
                                },
                                new Ext.form.TextField({
                                    id: "isbBoxNumberId",
                                    name: "isbBoxNumber",
                                    value: plasmidHash.isbBoxNumber,
                                    width: 75,
                                    allowBlank: false,
                                    listeners: {
                                        render: function(c) {
                                            Ext.QuickTips.register({
                                                target: c,
                                                title: '',
                                                text: 'ISB Assigned Strain box number'
                                            });
                                        }
                                    }
                                }),
                                {
                                    xtype: 'displayfield',
                                    value: '&nbsp;Position:&nbsp;'
                                },
                                new Ext.form.TextField({
                                    id: "positionId",
                                    name: "position",
                                    value: plasmidHash.position,
                                    width: 75,
                                    allowBlank: true,
                                    listeners: {
                                        render: function(c) {
                                            Ext.QuickTips.register({
                                                target: c,
                                                title: '',
                                                text: 'Plasmid physical position'
                                            });
                                        }
                                    }
                                })
                            ]
                        },
                        new Ext.form.DateField({
                            id: "dateEnteredId",
                            fieldLabel: "Date Frozen",
                            name: "dateEntered",
                            value: plasmidHash.dateEntered,
                            size: 20,
                            allowBlank: true
                        }),
                        {
                            xtype:'htmleditor',
                            id:'plasmidReferencesId',
                            value: plasmidHash.references,
                            labelSeparator: '',
                            fieldLabel:'References ' + '<br><i><font size=-2>Publications referencing and/or describing the plasmid. Add links to PubMed ID,  pdf  when available</font></i>',
                            height:100,
                            anchor:'98%',
                            listeners: {
                                activate: function(e) {
                                    if (plasmidHash.references == undefined || plasmidHash.references == "") {
                                        e.execCmd('delete');
                                    }
                                }
                            }
                        },
                        {
                            xtype:'htmleditor',
                            id:'mtaId',
                            labelSeparator: '',
                            value: plasmidHash.mta,
                            fieldLabel:'Legal Documents ' + '<br><i><font size=-2>link to Material Transfer Agreement or other legal documentation</font></i>',
                            height:100,
                            anchor:'98%',
                            listeners: {
                                activate: function(e) {
                                    if (plasmidHash.mta == undefined || plasmidHash.mta == "") {
                                        e.execCmd('delete');
                                    }
                                }
                            }
                        },
                        {
                            xtype:'htmleditor',
                            id:'plasmidCommentsId',
                            value: plasmidHash.comments,
                            fieldLabel:'Comments ' + '<br><i><font size=-2>Relevant information about the plasmid not covered in other fields, including relevant Euroscarf references</font></i>',
                            height:100,
                            labelSeparator: '',
                            anchor:'98%',
                            listeners: {
                                activate: function(e) {
                                    if (plasmidHash.comments == undefined || plasmidHash.comments == "") {
                                        e.execCmd('delete');
                                    }
                                }
                            }
                        }
                    ]
                })
            ]
        });
        callback();
    }

    // render the grid to the specified div in the page
    function renderPlasmidSearchResult() {
        var searchResultsButton = Ext.getCmp("showPlasmidSearchResultsId");
        if (searchResultsButton != null || searchResultsButton != undefined) {
            searchResultsButton.disable();
        }
        var mytbar = [
            {
                id: 'plasmid2CSVId',
                text: 'Export2CSV',
                icon: "images/check-green.png",
                cls:'x-btn-text-icon',
                tooltip: 'Export search results to csv',
                listeners: {click:
                        function() {
                            Dudley.lims.PlasmidStrain.toCSV();
                        }
                }
            }
        ];
        var searchResultsGrid = new Ext.grid.GridPanel({
            id: "plasmidSearchResultsId",
            store: plasmidStore,
            columns: getPlasmidSearchColumnHeaders(),
            stripeRows: true,
            autoHeight: true,
            width: 800,
            title: 'Plasmid',
            renderTo: "sample-search-result-list",
            bbar: new Ext.PagingToolbar({
                pageSize: 10,
                store: plasmidStore,
                displayInfo: true,
                displayMsg: 'Displaying strains {0} - {1} of {2}',
                emptyMsg: "No strains to display"
            }),
            tbar: mytbar
        });
        searchResultsGrid.on("celldblclick", function (g, ri, ci, e) {
            var searchResultsButton = Ext.getCmp("showPlasmidSearchResultsId");
            searchResultsButton.enable();
            plasmidHash = new Object();
            populatePlasmidJson(plasmidHash, g);
            var resourceUri = "/addama-rest/dudley-sample/path/datasource/Plasmid/" + plasmidHash.name;
            Ext.Ajax.request({
                url: resourceUri + "/mayUpdate",
                method: "GET",
                params: {
                    "user_uri": LoggedInUser.userUri
                },
                success: function() {
                    loadCreatePlasmidStrain(plasmidHash, function() {
                        plasmidFormRender();
                    });
                },
                failure: function() {
                    eventManager.fireStatusMessageEvent({ text: "Read only access allowed", level: "info" });
                    loadCreatePlasmidStrain(plasmidHash, function() {
                        var updatePlasmidButton = Ext.getCmp("updatePlasmidButtonId");
                        if (updatePlasmidButton != undefined) {
                            updatePlasmidButton.hidden = true;
                        }
                        var deletePlasmidButton = Ext.getCmp("deletePlasmidButtonId");
                        if (deletePlasmidButton != undefined) {
                            deletePlasmidButton.hidden = true;
                        }
                        plasmidFormRender();
                    });
                }
            });

        });
    }

    function plasmidFormRender() {
        Dudley.lims.samplemgr.getHousingPanel().activate(plasmidPanel);
        Ext.getDom("sample-search-result-list").innerHTML = "";
        Ext.getDom("yo-form").innerHTML = "";
        plasmidForm.render("yo-form");
    }
    
    function setupNewPlasmid(jsonObj){
    	limsadmin_obj =  jsonObj;
    	plasmidCount = jsonObj.limsadminPlasmidCount;
        plasmidMaxNum = jsonObj.limsadminPlasmidMaxNum;
        plasmidBoxNum = jsonObj.limsadminPlasmidBoxNum;
                        plasmidHash = null;
                        Ext.getCmp("showPlasmidSearchResultsId").enable();
                        loadCreatePlasmidStrain(plasmidHash, function() {
                            Ext.getDom("sample-search-result-list").innerHTML = "";
                            Ext.getDom("yo-form").innerHTML = "";
                            plasmidForm.render("yo-form");
                        });
     }                   

    // public
    return {
        initPlasmid: function(failedCB) {
            initPlasmidStore(failedCB, function() {
                eventManager.fireStatusMessageEvent({ text: "Finishing init Plasmid Store", level: "info" });
            });
        },

        getPlasmidPanel: function() {
            loadPlasmidPanel();
            return plasmidPanel;
        },

        getPlasmidStore: function() {
            return plasmidStore;
        },
        updateMTA: function(key, link){
            updateMTAWithKey("plasmidKey:" + key, plasmidFields, "plasmidMTA", link)
        },
        loadNewPlasmid: function() {
            Ext.getDom("yo-form").innerHTML = "";
            if (LoggedInUser.userUri == "/addama-users/users/public@systemsbiology.org") {
                Ext.Msg.alert("warning", "You not have permission to create new plasmids");
            } else {
             	getSolrLimsAdmin(setupNewPlasmid);   
            }
        },
        loadSearchResult: function() {
            Ext.getDom("sample-search-result-list").innerHTML = "";
            renderPlasmidSearchResult();
        },
        toCSV: function() {
            var csvText = "plasmidKey,plasmidName,plasmidMarkers,plasmidYeastSelection,plasmidBoxNumber,plasmidDateEntered," +
                          "plasmidBacterialHost,plasmidContributor,plasmidSavedBy,plasmidYeastOrigin,plasmidBacterialSelection," +
                          "plasmidComments,plasmidReferences,plasmidPosition,plasmidAccessionId,plasmidMTA,plasmidIsbBoxNumber" + breakDelimiter;
            myPlasmidData.sort(function(a, b) {
                return a[0] - b[0];
            });
            for (var c = 0; c < myPlasmidData.length; c++) {
                var cArray = myPlasmidData[c];
                var pline = "";
                for (var ci = 0; ci < cArray.length; ci++) {
                    if (cArray[ci] == undefined || cArray[ci] == null) {
                        cArray[ci] = "";
                    }
                    cArray[ci] = cArray[ci] + "";
                    cArray[ci] = cArray[ci].replace(/'/g, "");
                    cArray[ci] = '"' + cArray[ci] + '"';
                    if (ci > 0){
                    	pline = pline + cArray[ci] + ",";
                    }
                }
                csvText = csvText + pline.substr(0, pline.length - 1) + breakDelimiter;
            }
            export2Csv("PlasmidSearchedResults.csv", csvText, "Plasmid2Csv");
        },
        setArrayData: function(data) {
                    myPlasmidData = data;
         }
    };
}();
